{# templates>blog>post>detail.html #}
{% extends "blog/base.html" %} 
{% load blog_tags %}
{% block title %}{{ post.title }}{% endblock %}
{% block content %} 
  <h1>{{ post.title }}</h1> 
  <p class="date">
    通过{{ post.author }}帖子发布日期{{ post.publish }}
  </p> 
  {{ post.body|markdown|safe}}
    <p>
  <a href="{% url "blog:post_share" post.id %}">
    分享博文
  </a>
</p>
        <h2>相似帖子</h2>
    {% for post in similar_posts %}
        <p>
        <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
        </p>
     {% empty %}
        目前没有相似的帖子
    {% endfor %}

     {% with comments.count as total_comments %}
    <h2>
      已有评论:{{ total_comments }}
    </h2>
  {% endwith %}
    {% for comment in comments %}
    <div class="comment">
      <p class="info">
        Comment {{ forloop.counter }} by {{ comment.name }}
        {{ comment.created }}
      </p>
      {{ comment.body|linebreaks }}
    </div>
    {% empty %}{# 遍历的列表为空，会走这里 #}
    <p>目前尚无评论</p>
  {% endfor %}
  {% if new_comment %}
    <h2>你的评论已经添加了</h2>
  {% else %}
    <h2>添加新的评论</h2>
      <form action="{{ path }}" method="post" >
        {% csrf_token %}
        {{ comment_form.as_p }}
      <p><input type="submit" value="提交评论"></p>
    </form>
  {% endif %}
{% endblock %}